package com.hxh.component.basicore.component.net;

import com.hxh.component.basicore.ui.livedata.LiveDataBus;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Response;

/**
 * 请求拦截器，作用：
 * 当你想在请求前或者请求后做一些事情的时候，那么你就注册
 */
public class RequestCodeInterceptor implements Interceptor {

    //请求成功，但没有处理
    public static final int HTTP_CODE_200 = 200;
    public static final int HTTP_CODE_404 = 404;
    public static final int HTTP_CODE_500 = 500;

    @Override
    public Response intercept(Chain chain) throws IOException {
        Response response = chain.proceed(chain.request());

        LiveDataBus.get().with("error_code").postValue(response.code());

        return response;
    }

}
